#ifndef APP_H
#define APP_H
	
	#include "hardware.h"
	#include "led.h"
	#include "serial.h"
	#include "hal_adc.h"
	#include "pwm_out.h"
	#include "LowerFilter.h"
	#include "read_pwm.h"
	#include "radioprotocol.h"
	#include "param.h"
	
	#define ANG1_MAX   3.5f
	#define ANG1_MIN   1.5f
	#define ANG1_MID   2.5f

	#define ANG1_LIMT_MAX 3.1f
	#define ANG1_LIMT_MIN 1.7f
	
	#define RC_IN_MIN 800
	#define RC_IN_MAX 2200
	#define RC_IN_DZ  30

	#define PWM_IN_MIN 800
	#define PWM_IN_MAX 2200
	#define PWM_IN_MID ((2200-800)/2+800)
	#define PWM_IN_CYCLE 22000u
	
	typedef struct 
	{
		float current_motor_ang1;
		int16_t motor_target;  //-1000 - 0 -1000		
	}ControlSystem;
	
	extern ControlSystem control_system;
	extern LowerFilter angle_lower_filter1;
	extern LowerFilter angle_lower_filter2;
	extern RadioProtocolDataParse radio_parse;
	extern RadioProtocolData radio_data_rx;
	
	extern Param system_param;
	extern const param_list _param_list;
	
	extern pwm_in_timer pwm_in;
	extern rc_channel rc_in;
	
	void app_init(void);
	
	void app(void);
	
	void app_timer_callback(void);
	
	void motor_control(void);
	
	void update_batt_sensor(void);
	void update_angle_sensor(void);
	float get_batt_vol(void);
	float get_motor_current(void);
	float get_ang1_col(void);
	float get_an2_vol(void);
	void adc_process_test(void);
	
	void rc_channel_init(void);
	void update_rc_channel(void);
	
	float float_mid(float min, float value,float max);

#endif
